Class SparseMatrix
- java.lang.Object
-
- edu.claflin.finder.logic.communities.struct.SparseMatrix
-
public class SparseMatrix extends java.lang.ObjectSparseMatrix is a sparse matrix with row format.
-
-
Field Summary
Fields Modifier and Type Field Description java.util.HashMap<java.lang.Integer,java.util.PriorityQueue<HeapNode>>heapsjava.util.HashMap<java.lang.Integer,BinarySearchTree>trees
-
Constructor Summary
Constructors Constructor Description SparseMatrix(int rows)empty sparse matrix with allocated number of rows
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int i, int j, double q)Add the given j index, q value pair to the ith tree and heapvoidaddHeap(int i, int j, double q)Add the given j index, q value pair to the ith heap.voidaddTree(int i, int j, double q)Add the given j index, q value pair to the ith tree.java.lang.Doubleget(int i, int j)get number at index or null if not set.HeapNodegetMax(int i)Get the maximum q value at row ivoidmergeTrees(int j, int i)Merge Trees j and i into j, summing values if the same column occurs.voidrebuildHeap(int j)Rebuild heap j with the tree jvoidremove(int i)Remove the ith rowprivate voidremoveFromTree(int i, int j)voidset(int i, int j, double q)Set the q value at the ith tree and heap's j column.voidsetHeap(int i, int j, double q)Set the value q and the ith heap's j column.voidsetTree(int i, int j, double q)Set value q and the ith tree's j column.java.lang.StringtoString()
-
-
-
Field Detail
-
heaps
public java.util.HashMap<java.lang.Integer,java.util.PriorityQueue<HeapNode>> heaps
-
trees
public java.util.HashMap<java.lang.Integer,BinarySearchTree> trees
-
-
Method Detail
-
add
public void add(int i, int j, double q)Add the given j index, q value pair to the ith tree and heap- Parameters:
i- the row to addj- the j indexq- the q value
-
addTree
public void addTree(int i, int j, double q)Add the given j index, q value pair to the ith tree.- Parameters:
i- the row to addj- the j indexq- the q value
-
addHeap
public void addHeap(int i, int j, double q)Add the given j index, q value pair to the ith heap.- Parameters:
i- the row to addj- the j indexq- the q value
-
get
public java.lang.Double get(int i, int j)get number at index or null if not set.- Parameters:
i- the row to searchj- the colum to search- Returns:
- the q value if it exists or null
-
setTree
public void setTree(int i, int j, double q)Set value q and the ith tree's j column. add it if it's not there.- Parameters:
i- the row to set inj- the column to set inq- the new q value
-
setHeap
public void setHeap(int i, int j, double q)Set the value q and the ith heap's j column. add it if it's not there.- Parameters:
i- the row to set inj- the column to set inq- the new q value
-
set
public void set(int i, int j, double q)Set the q value at the ith tree and heap's j column.- Parameters:
i- the row to set inj- the column to set inq- the new q value
-
removeFromTree
private void removeFromTree(int i, int j)
-
getMax
public HeapNode getMax(int i)
Get the maximum q value at row i- Parameters:
i- the row to search in- Returns:
- the maximum q value
-
remove
public void remove(int i)
Remove the ith row- Parameters:
i- the row to clear in
-
mergeTrees
public void mergeTrees(int j, int i)Merge Trees j and i into j, summing values if the same column occurs.- Parameters:
j- the tree to expandi- the tree that offers its Nodes
-
rebuildHeap
public void rebuildHeap(int j)
Rebuild heap j with the tree j- Parameters:
j- the heap to rebuild
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-